package com.idp.web.test.service.impl;
import com.idp.web.test.service.SafeWarningService;
import com.idp.web.test.dao.SafeWarningDao;
import com.idp.web.test.entity.SafeWarning;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.idp.common.persistence.Page;

/**
 * 
 * 安全库存预警service实现类
 * 
 * <pre>
 * 	历史记录：
 * 	2017-06-06 Amber
 * 	新建文件
 * </pre>
 * 
 * @author 
 * <pre>
 * SD
 * 	Amber
 * PG
 *	Amber
 * UT
 *
 * MA
 * </pre>
 * @version $Rev$
 *
 * <p/> $Id$
 *
 */
@Service("safeWarningService")
public class SafeWarningServiceImpl implements SafeWarningService {

	@Resource
	private SafeWarningDao safeWarningDao;
	
	@Override
	public Page<SafeWarning> findByPage(SafeWarning safeWarning, Page<SafeWarning> page) {

		page.setResult(safeWarningDao.find(safeWarning, page));
		
		return page;
	}
	
	@Override
	public List<SafeWarning> findBySearch(SafeWarning safeWarning) {
		List<SafeWarning> result = safeWarningDao.find(safeWarning);
		for(SafeWarning sw : result) {
			if(sw.getStock().getStockNum() >= sw.getWarningMin() && sw.getStock().getStockNum() <= sw.getWarningMax()) {
				sw.setIsNormal("true");
			}
		}
		return result;
	}
	
	@Override
	public SafeWarning getById(Integer id) {

		return safeWarningDao.getById(id);
	}

	@Override
	public void add(SafeWarning safeWarning) {

		safeWarningDao.add(safeWarning);
	}
	
	@Override
	public void update(SafeWarning safeWarning) {

		safeWarningDao.update(safeWarning);
	}

	@Override
	public void delete(Integer id) {

		safeWarningDao.delete(id);
	}
 	
}